package com.wnxy.sddfp.system.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.wnxy.sddfp.common.util.JwtTemplate;
import feign.Logger;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.client.RestTemplate;

@Configuration
public class SystemConfig {
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    public JwtTemplate jwtTemplate() {
        return new JwtTemplate();
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }

    /**
     * openfeign通讯日志, 查看根据日志级别显示日志内容
     */
    @Bean
    public Logger.Level loggingLevel(){
        return Logger.Level.FULL;
    }

    //在启动类或配置类中注入负载均衡策略对象。所有服务请求均使用该策略。 (如果配置了局部也配置了全局，以全局配置为准)
    @Bean
    public IRule rules(){
        return new RandomRule();
    }
}
